<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .drag-box {
        height: 50px;
        margin: 5px;
        background-color: rgb(243, 243, 248);
        border: 1px solid black;
        cursor: move;
      }

      .drag-box.dragging {
        opacity: 0.5;
        background-color: salmon;
      }
    </style>
  </head>
  <body>
    <div class="content">
      <div class="drag-box" draggable="true">1</div>
      <div class="drag-box" draggable="true">2</div>
      <div class="drag-box" draggable="true">3</div>
      <div class="drag-box" draggable="true">4</div>
      <div class="drag-box" draggable="true">5</div>
      <div class="drag-box" draggable="true">6</div>
      <div class="drag-box" draggable="true">7</div>
      <div class="drag-box" draggable="true">8</div>
      <div class="drag-box" draggable="true">9</div>
      <div class="drag-box" draggable="true">10</div>
    </div>

    <script>
      const content = document.querySelector(".content");
      let draggingBox = null;

      content.addEventListener("dragstart", (e) => {
        e.target.classList.add("dragging");
        draggingBox = e.target;
      });

      content.addEventListener("dragover", (e) => {
        e.preventDefault();
        const positionY = e.clientY - draggingBox.getBoundingClientRect().top;
        if (positionY > draggingBox.offsetHeight / 2) {
          content.insertBefore(draggingBox, e.target.nextElementSibling);
        } else {
          content.insertBefore(draggingBox, e.target);
        }
      });

      content.addEventListener("dragend", (e) => {
        draggingBox.classList.remove("dragging");
        draggingBox = null;
      });
    </script>
  </body>
</html>
